//<template>
    <div>
        <div>
            <tr>
                <td>产品名</td>
                <td>产品价格</td>
                <td>数量</td>
                <td>小计</td>
            </tr>
            <tr v-for="i in cart_list" :key="i.id">
                <td>{{i.product.good}}</td>
                <td>{{i.product.price}}</td>
                <td>{{i.num}}</td>
                <td>{{m_price}}</td>
            </tr>
        </div>
        <div>
            <p>总价格{{ sum_price }}</p>
        </div>
        <div>
            <select v-model="cou_id">
                <option v-for="i in cou_list" :key="i.id" :value="i.id">{{ i.cou }}</option>
            </select>
        </div>
        <div>
            实际要支付的金额：
            <div v-if="cou_id == 1">{{ sum_price-5 }}</div>
            <div v-if="cou_id == 2">{{ sum_price-10 }}</div>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return{
            cou_list:[],
            cart_list:[],
            id:sessionStorage.getItem('user_id'),
            url:'http://127.0.0.1:8000',
            num:1,
            cou_id:''
        }
    },
    computed:{
        sum_price(){
            let total_sum = 0
            for(let b in this.cart_list){
                total_sum += this.cart_list[b].product.price * this.cart_list[b].num
            }
            return total_sum
        },
        m_price(){
            let total_num = 0
            for(let b in this.cart_list){
                total_num = this.cart_list[b].product.price * this.cart_list[b].num
            }
            return total_num
        }
    },
    methods:{
        orderShow(){
            axios({
                url:'http://127.0.0.1:8000/workapp/cart_show/?user_id=' + this.id
            }).then(res=>{
                console.log(res.data)
                this.cart_list = res.data.cart_list
                this.cou_list = res.data.cou_list
            })
        },
    },
    created(){
        this.orderShow()
    }
}
</script>

<style>

</style>